﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>检查物料编码有效性</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>
<body>
	<div id="msg" align="center" style="padding-top: 40px;">
		正在验证物料编码……</div>
	<script type="text/javascript">
	var upWindow = window.parent.frames["zwIframe"];
	if (!upWindow) {
    try {
        upWindow = window.parent.frames["componentDiv"].frames["zwIframe"];
    } catch (e) {
        upWindow = null;
    }
}
	var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";
	
	function fy_dialog_close(){
		window.parent.$(".mask").remove();
		window.parent.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger("click");
	}
		function getUpFieldsByFieldval(name) {
			return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
		}

		function getUpFieldValue(field) {
			var fieldVal = field.attr("fieldVal");
			var editTag = field.hasClass(editClass);
			var browseTag = field.hasClass(browseClass);
			var addTag = field.hasClass(addClass);
			if (fieldVal != null && typeof (fieldVal) != 'undefined') {
				fieldVal = eval("(" + fieldVal + ")");
			} else {
				return null;
			}
			var obj = new Object();
			obj.displayName = fieldVal.displayName;
			obj.name = fieldVal.name;
			var tag = true;
			switch (fieldVal.inputType) {
			case "text":
			case "textarea":
				if (editTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				} else if (browseTag) {
					obj.value = fieldVal.value;
				} else if (addTag) {
					obj.value = field.find("#" + fieldVal.name).val();
				}
				break;
			default:
				tag = false;
			}
			if (obj.value != undefined) {
				obj.value = obj.value.replace("\r\n", ";");
				obj.value = obj.value.replace("\n", ";");
			}
			return obj;
		}
		
		function setUpFieldValue2(field, value, displayValue, index) {
				var fieldVal = field.attr("fieldVal");
				var editTag = field.hasClass(editClass);
				var browseTag = field.hasClass(browseClass);
				var addTag = field.hasClass(addClass);
				if (fieldVal != null && typeof (fieldVal) != 'undefined') {
					fieldVal = eval("(" + fieldVal + ")");
				} else {
					return null;
				}
				var tag = true;
				switch (fieldVal.inputType) {
				case "text":
				case "textarea":
					if (editTag) {
						field.find("#" + fieldVal.name).val(value);
						field.find("#" + fieldVal.name).trigger("blur");
					} else if (addTag) {
						field.find("#" + fieldVal.name).val(
								field.find("#" + fieldVal.name).val() + value);
						field.find("#" + fieldVal.name).trigger("blur");
					}
					break;
				case "date":
					if (editTag) {
						field.find("#" + fieldVal.name).val(value);
						field.find("#" + fieldVal.name).trigger("blur");
					}
					break;
				}
		}

		var materialCode = [];
		var xmlObj = null;
		var DifferentiateForm = false;
		<!--供应商送样评定表-->
		var materialCodeInputArray = getUpFieldsByFieldval("物料编码");
		var materialNameInputArray = getUpFieldsByFieldval("物料名称");
		/* var materialTypeInputArray = getUpFieldsByFieldval("MDM物料类别");
		<!--集团物料编码变更申请表-->
		var oldMaterialCodeInputArray = getUpFieldsByFieldval("原编码");
		var oldMaterialDescribeInputArray = getUpFieldsByFieldval("原说明");
		var oldMaterialDescribeEnInputArray = getUpFieldsByFieldval("英文原说明");
		var oldMaterialMeasurementInputArray = getUpFieldsByFieldval("原单位"); */
		
		/* var newMaterialCodeInputArray = getUpFieldsByFieldval("需改成的编码");
		var newMaterialDescribeInputArray = getUpFieldsByFieldval("需改成的说明");
		var newMaterialDescribeEnInputArray = getUpFieldsByFieldval("英文需修改成的说明");
		var newMaterialMeasurementInputArray = getUpFieldsByFieldval("需修改成的单位"); */
		
		
		if(materialCodeInputArray.length>0){
			//DifferentiateForm=true;
			length = materialCodeInputArray .length; 
			
		}/* else{
			length = oldMaterialCodeInputArray .length; 
		} */
		
		function init() {
			for ( var i = 0;i < length; i++) {
			//	if(DifferentiateForm){
				materialCode.push(getUpFieldValue(materialCodeInputArray .eq(i)).value);
				setUpFieldValue2(materialNameInputArray.eq(i),"");
			/* 	setUpFieldValue2(materialTypeInputArray.eq(i), "");
				}else{
					materialCode.push(getUpFieldValue(oldMaterialCodeInputArray .eq(i)).value);
					setUpFieldValue2(oldMaterialDescribeInputArray.eq(i), "");
					setUpFieldValue2(oldMaterialMeasurementInputArray.eq(i), "");
					setUpFieldValue2(oldMaterialDescribeEnInputArray.eq(i), "");
				} */
			}
		}

		function load() {
			if (window.XMLHttpRequest) {
				xmlObj = new XMLHttpRequest();
			} else {
				if (window.ActiveXObject) {
					xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
				} else {
					return;
				}
			}
			xmlObj.onreadystatechange = handleResponse;
			
			xmlObj.open("get",
					"./oa2mdmController.do?method=writeSrmBCategoryJSP&materialCode="+ materialCode.join(","), true);
			xmlObj.send();

		}
		
		function handleResponse() {
			if (xmlObj.readyState == 4) {//xmlObj loaded
				var success = false;
				if (xmlObj.status == 200) {
					var datas = eval("[" + xmlObj.responseText + "]");
					if (datas.length == 1) {
						var materialMap = datas[0];
						for ( var i = 0; i < length; i++) {
				
						//	if(DifferentiateForm){
							var  material =materialMap["materialCode"
									+ getUpFieldValue(materialCodeInputArray.eq(i)).value];
							if(material){
								setUpFieldValue2(materialNameInputArray.eq(i),
										material["materialName"]);	
							/* 	setUpFieldValue2(materialTypeInputArray.eq(i),
										material["first_category"]);	 */
								/* }else{
									var  material =materialMap["materialCode"
										+ getUpFieldValue(oldMaterialCodeInputArray.eq(i)).value];
								if(material){
									setUpFieldValue2(oldMaterialDescribeInputArray.eq(i),
											material["materiel_describe"]);	
									setUpFieldValue2(oldMaterialMeasurementInputArray.eq(i),
											material["measurement"]);
									setUpFieldValue2(oldMaterialDescribeEnInputArray.eq(i),
											material["materiel_describe_en"]);
								}} */
									
						}
							success = true;	
						}
				}
			}
				if (!success) {
					alert("请检查输入的物料 ");
				}
				fy_dialog_close();
			}
		
		}
		init();
		load();
	</script>
</body>
</html>

</html>